package cn.cocho.android.mc.comp.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.TextView;

import cn.cocho.android.mc.R;

/**
 * 自定义对话框
 * 
 * @author hsx
 * @time 2013-5-7下午02:29:07
 */
public class McDialog extends AlertDialog {
	TextView tv_dialog_title;
	TextView tv_dialog_message;
	Button tv_btn_dialog_sure;
	LayoutInflater inflater;
	View view;

	public McDialog(Context context) {
		super(context);
		inflater = LayoutInflater.from(context);
		view = inflater.inflate(R.layout.mc_dialog_layout, null);
		initWidget();
		setPositiveButton("确定");
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(view);
	}

	private void initWidget() {
		tv_dialog_title = (TextView) view.findViewById(R.id.flat_dialog_title);
		tv_dialog_message = (TextView) view.findViewById(R.id.flat_dialog_content);
		tv_btn_dialog_sure = (Button) view.findViewById(R.id.flat_dialog_ok_btn);

	}

	@Override
	public void setTitle(CharSequence title) {
		tv_dialog_title.setText(title);
		super.setTitle(title);
	}

	@Override
	public void setMessage(CharSequence message) {
		tv_dialog_message.setText(message);
		super.setMessage(message);
	}

	public void setPositiveButton(CharSequence text, View.OnClickListener listener) {
		tv_btn_dialog_sure.setText(text);
		tv_btn_dialog_sure.setOnClickListener(listener);
	}

	public void setPositiveButton(CharSequence text) {
		tv_btn_dialog_sure.setText(text);
		tv_btn_dialog_sure.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				cancel();
				dismiss();
			}
		});
	}

	@Override
	public void onWindowAttributesChanged(LayoutParams params) {

		super.onWindowAttributesChanged(params);

	}

}
